home *** CD-ROM | disk | FTP | other *** search
- Path: tech.cftnet.com!not-for-mail
- From: wcowley@cftnet.com (Wes Cowley)
- Newsgroups: comp.lang.c++
- Subject: Re: Help needed: reference parameter
- Date: 4 Mar 1996 11:03:28 GMT
- Organization: CFTnet
- Message-ID: <4heim1$nqr@tech.cftnet.com>
- References: <4gv7al$o0c$1@mhafc.production.compuserve.com>
- NNTP-Posting-Host: ppp244_4.cftnet.com
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Terry Nikkel (102101.2325@CompuServe.COM) wrote:
- : I am posting this for a colleague, thanks for your help:
- : I want to pass a reference (default 0) parameter to a function.
- : For example, assume classes 'AClass' and 'BClass'; assume
- : 'AClass' has a method called 'Function'.
- :
- : //AClass.hxx
- : #include "BClass.hxx"
- : bool AClass::Function (BClass& = 0); // would be the
- : specification
- :
- : //AClass.cxx
- : bool AClass::Function (BClass& refer) // is the actual method
- : {
- : if (! (refer == 0) {
- : ...
- : {
- : }
-
- The problem is that 0 is not a valid value for references. For pointers,
- 0 is used as the null pointer but it doesn't work that way for references.
- One technique that might be appropriate for you is to define a dummy
- instance of BClass that is treated as a missing reference:
-
- class BClass {
- ...
- static BClass nullBClass;
- ... };
-
- BClass BClass::nullBClass;
-
- bool AClass::Function(BClass& = BClass::nullBClass);
-
- Wes
-